defmodule EliPhxPlay.Repo.Migrations.AddGroupCodeToGroups do
  use Ecto.Migration

  def change do
    # 添加群号字段
    alter table(:groups) do
      add :group_code, :string, comment: "用户友好的群号，8位数字"
    end

    # 只创建唯一索引即可，它也能提供查询性能
    create unique_index(:groups, [:group_code], comment: "群号唯一性约束")
  end

  def down do
    # 回滚时删除索引和字段
    drop unique_index(:groups, [:group_code])

    alter table(:groups) do
      remove :group_code
    end
  end
end
